<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;
use Auth;

class ShopLoginController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function postLogin(Request $request)
    {
        //检测当前是否有用户登录.如果有,注销登录
        if(Auth::check()){
            Auth::logout();
        }
        //商家登录
        // dd($request);
        $shopName = $request->name;
        $pwd = md5($request->password);
        if(!empty($shopName)){
            $res = DB::table('shop')->where('shop_name',$shopName)->first();
            if($res){
                $shop_pwd = $res->shop_pwd;
                //dd($shop_pwd);
                if($pwd == $shop_pwd){
                    $request->session()->put('shopInfo',$res);
                   // dd(session()->get('shopInfo'));
                    return redirect('shopInfo');
                }else{
                    return back()->with('msg',"用户名或密码错误");

                }
            }else{
                return back();
            }
        }else{
            return back()->with('msg',"用户名不存在");
        }
    }

    public function shopLogout()
    {
        session()->forget('shopInfo');
        return redirect('/');
    }

   
    
}
